<?
/**
* 获取上级权限的信息
* @param pid	权限id
* @param id		不需要显示的权限的id
* @return Array
*/
function getParentPermission($pid=0,$id=0)
{
	$t=new Tbl_Act('mem_permissions','id');
	$conv=" where 1 ";
	if($pid<=0)
	{
		$conv.="";
	}
	else
	{
		$conv.=" and parent_id='$pid'";
	}
	if($id>0)
	{
		$conv.=" and permissions_id<>'$id'";
	}
	$rows=$t->GetAll('*'," where parent_id='$pid' and permissions_id<>'$id' order by permissions_id asc");
	return $rows; 
}

/**
* 生成上级权限列表html
* @param pid	权限id
* @param id		不需要显示的权限的id
* @param cid	已经选中id
* @return Array
*/
function  getParentPermissionList($pid=0,$id=0,$cid)
{
	$rows= getParentPermission($pid,$id);
	if(is_array($rows))
	{
		$ss='';
		foreach($rows as $key => $row)
		{
			if($row['permissions_id']==$cid)
			{
				$ss.='<option value="'.$row['permissions_id'].'" selected>'.$row['name'].'</option>'."\n";
			}
			else
			{
				$ss.='<option value="'.$row['permissions_id'].'">'.$row['name'].'</option>'."\n";
			}
		}
	}
	return $ss;
}


/**
* 取得下一级权限的等级
*/
function getLastGrade($pid)
{
	$t=new Tbl_Act('mem_permissions','id');
	$t->permissions_id=$pid;
	$t->GetOne(array("permissions_id,="));
	$grade=$t->grade;
	$grade=$grade+1;
	return $grade;
}

/**
* 获取类别名称
* @param pid	类别
* @return String
*/
function getNameByPid($pid)
{
	if($pid==0)
	{
		return '-';
	}
	global $db;
	$sql="select name from mem_permissions where permissions_id='$pid' limit 0,1";
	$rs=$db->Execute($sql);
	if($rs && $row=$rs->FetchRow())
	{
		return $row['name'];
	}
	else
	{
		return '-';
	}
}
?>